package org.pgis.gui;

import javax.swing.JPanel;
import javax.swing.JLabel;

import org.pgis.core.AbstractScenePanel;

import java.awt.Font;
import javax.swing.JSlider;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

public class ClippingPanel extends JPanel{

	private static final long serialVersionUID = 1L;
	private AbstractScenePanel asp;
	public ClippingPanel(AbstractScenePanel asp) {
		this.asp = asp;
		initialize();
	}

	private void initialize() {

		this.setLayout(null);

		JLabel labelColor = new JLabel("Clipping");
		labelColor.setFont(new Font("Century", Font.BOLD, 16));
		labelColor.setBounds(76, 11, 162, 30);
		this.add(labelColor);

		JSlider sliderXminus = new JSlider();
		sliderXminus.setValue(asp.getSim().getClipXminus());
		sliderXminus.setPaintLabels(true);
		sliderXminus.setPaintTicks(true);

		sliderXminus.setBounds(40, 56, 200, 21);
		sliderXminus.addChangeListener(new ChangeListener() {
            public void stateChanged(ChangeEvent evt) {
                JSlider slider = (JSlider) evt.getSource();
                int value = slider.getValue();
                asp.getSim().setClipXminus(value);
                asp.refresh();
            }
        });
		add(sliderXminus);

		JSlider sliderXplus = new JSlider();
		sliderXplus.setValue(asp.getSim().getClipXplus());
		sliderXplus.addChangeListener(new ChangeListener() {
			public void stateChanged(ChangeEvent evt) {
				JSlider slider = (JSlider) evt.getSource();
                int value = slider.getValue();
                asp.getSim().setClipXplus(value);
                asp.refresh();
			}
		});
		sliderXplus.setPaintTicks(true);
		sliderXplus.setPaintLabels(true);
		sliderXplus.setBounds(40, 88, 200, 21);
		add(sliderXplus);

		JSlider sliderYminus = new JSlider();
		sliderYminus.setValue(asp.getSim().getClipYminus());
		sliderYminus.addChangeListener(new ChangeListener() {
			public void stateChanged(ChangeEvent evt) {
				JSlider slider = (JSlider) evt.getSource();
                int value = slider.getValue();
                asp.getSim().setClipYminus(value);
                asp.refresh();
			}
		});
		sliderYminus.setPaintTicks(true);
		sliderYminus.setPaintLabels(true);
		sliderYminus.setBounds(40, 120, 200, 21);
		add(sliderYminus);

		JSlider sliderYplus = new JSlider();
		sliderYplus.setValue(asp.getSim().getClipYplus());
		sliderYplus.addChangeListener(new ChangeListener() {
			public void stateChanged(ChangeEvent evt) {
				JSlider slider = (JSlider) evt.getSource();
                int value = slider.getValue();
                asp.getSim().setClipYplus(value);
                asp.refresh();
			}
		});
		sliderYplus.setPaintTicks(true);
		sliderYplus.setPaintLabels(true);
		sliderYplus.setBounds(40, 152, 200, 21);
		add(sliderYplus);

		JSlider sliderZminus = new JSlider();
		sliderZminus.setValue(asp.getSim().getClipZminus());
		sliderZminus.addChangeListener(new ChangeListener() {
			public void stateChanged(ChangeEvent evt) {
				JSlider slider = (JSlider) evt.getSource();
                int value = slider.getValue();
                asp.getSim().setClipZminus(value);
                asp.refresh();
			}
		});
		sliderZminus.setPaintTicks(true);
		sliderZminus.setPaintLabels(true);
		sliderZminus.setBounds(40, 184, 200, 21);
		add(sliderZminus);

		JSlider sliderZplus = new JSlider();
		sliderZplus.setValue(asp.getSim().getClipZplus());
		sliderZplus.addChangeListener(new ChangeListener() {
			public void stateChanged(ChangeEvent evt) {
				JSlider slider = (JSlider) evt.getSource();
                int value = slider.getValue();
                asp.getSim().setClipZplus(value);
                asp.refresh();
			}
		});
		sliderZplus.setPaintTicks(true);
		sliderZplus.setPaintLabels(true);
		sliderZplus.setBounds(40, 216, 200, 21);
		add(sliderZplus);

		JLabel lblXminus = new JLabel("-X");
		lblXminus.setBounds(19, 56, 27, 14);
		add(lblXminus);

		JLabel lblXplus = new JLabel("+X");
		lblXplus.setBounds(19, 88, 27, 14);
		add(lblXplus);

		JLabel lblYminus = new JLabel("-Y");
		lblYminus.setBounds(19, 120, 27, 14);
		add(lblYminus);

		JLabel lblYplus = new JLabel("+Y");
		lblYplus.setBounds(19, 152, 27, 14);
		add(lblYplus);

		JLabel lblZminus = new JLabel("-Z");
		lblZminus.setBounds(19, 182, 27, 14);
		add(lblZminus);

		JLabel lblZplus = new JLabel("+Z");
		lblZplus.setBounds(19, 216, 27, 14);
		add(lblZplus);
	}
}
